package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.MineGoogleBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.MineChromeVerficationActivity;

public class MineChromeVerficationPresenter extends BasePresenter<MineChromeVerficationActivity> {
    // 获取信息接口
    public void bindGoogle(String id) {
        httpService.bindGoogle(id)
                .execute(new JsonCallBack<HttpData<MineGoogleBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<MineGoogleBean>> response) {
                        HttpData<MineGoogleBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateUi(httpData.getData());
                        }
                    }
                });
    }

    // 绑定谷歌
    public void bindChrome(String qrcode, String secret, String code, String stockUserId, String telCode) {
        httpService.bindChrome(qrcode, secret, code, stockUserId, telCode)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateUi();
                        }
                    }

                });
    }

    // 获取验证码
    public void sendCode(String mobile) {
        httpService.sendCode(mobile, "1", "3", mobile)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.sendCodeOk();
                        } else {
                            mView.sendCodeError();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        mView.sendCodeError();
                        super.onError(response);
                    }
                });
    }
}
